package com.ruoyi.employer.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.employer.domain.CargoConsigner;
import com.ruoyi.employer.service.ICargoConsignerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发货人信息Controller
 * 
 * @author adf
 * @date 2024-08-13
 */
@RestController
@RequestMapping("/employer/consigner")
public class CargoConsignerController extends BaseController
{
    @Autowired
    private ICargoConsignerService cargoConsignerService;

    /**
     * 查询发货人信息列表
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:list')")
    @GetMapping("/list")
    public TableDataInfo list(CargoConsigner cargoConsigner)
    {
        startPage();
        List<CargoConsigner> list = cargoConsignerService.selectCargoConsignerList(cargoConsigner);
        return getDataTable(list);
    }

    /**
     * 查询发货人信息列表
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:list')")
    @GetMapping("/listAll")
    public TableDataInfo listAll()
    {
        List<CargoConsigner> list = cargoConsignerService.selectCargoConsignerList(null);
        return getDataTable(list);
    }

    /**
     * 导出发货人信息列表
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:export')")
    @Log(title = "发货人信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CargoConsigner cargoConsigner)
    {
        List<CargoConsigner> list = cargoConsignerService.selectCargoConsignerList(cargoConsigner);
        ExcelUtil<CargoConsigner> util = new ExcelUtil<CargoConsigner>(CargoConsigner.class);
        util.exportExcel(response, list, "发货人信息数据");
    }

    /**
     * 获取发货人信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cargoConsignerService.selectCargoConsignerById(id));
    }

    /**
     * 新增发货人信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:add')")
    @Log(title = "发货人信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CargoConsigner cargoConsigner)
    {
        return toAjax(cargoConsignerService.insertCargoConsigner(cargoConsigner));
    }

    /**
     * 修改发货人信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:edit')")
    @Log(title = "发货人信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CargoConsigner cargoConsigner)
    {
        return toAjax(cargoConsignerService.updateCargoConsigner(cargoConsigner));
    }

    /**
     * 删除发货人信息
     */
    @PreAuthorize("@ss.hasPermi('employer:consigner:remove')")
    @Log(title = "发货人信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cargoConsignerService.deleteCargoConsignerByIds(ids));
    }
}
